<?php

namespace bc\wx;

class ArrayToXml
{
	
	const HEADER = '<xml>';
	
	const BOTTOM = '</xml>';
	
	/**
	 * 
	 * @param array $data
	 * @return string
	 */
	public function convert($data)
	{
		
		$xml = self::HEADER;
		
		if(is_array(data))
		{
			foreach ($data as $key=>$row)
			{
				$tmp = '<' . $key . '>';
				
				if($key == 'detail')
				{
					
					
					$tmp .= '<![CDATA';
					
					$tmp .= $row;
					
					$tmp .= ']]';
				}
				else 
				{
					$tmp .= $row;
				}
				
				$tmp .= '</' . $key . '>';
				
				$xml .= $tmp;
			}
		}
		
		$xml .= self::BOTTOM;
		return $xml;
	}
}

